/*
 * @Description: 
 * @FilePath: \网易云音乐e:\CSS+HTML+JS+\学习笔记\代码测试\算法\字符串\164.最大间距.js
 */ 
/*
 * @lc app=leetcode.cn id=164 lang=javascript
 *
 * [164] 最大间距
 */

// @lc code=start
/**
 * @param {number[]} nums
 * @return {number}
 */
var maximumGap = function(nums) {
    let len = nums.length;
    if(len < 2) return 0;

    let max = 0;
    for(let i = 0; i < len-1; i++) {
        for(let j = 0; j < len-1-i; j++) {
            if(nums[j] >= nums[j+1]) {
                nums[j+1] = nums[j] + nums[j+1];
                nums[j] = nums[j+1] - nums[j];
                nums[j+1] = nums[j+1] - nums[j];
            }
        }
        if(i != 0) {
            max = Math.max(nums[len-i]-nums[len-1-i], max);
        }
    }
    max = Math.max(nums[len-1]-nums[len-2], max);
    console.log(max);

    return max;
};
let res = maximumGap([3,1]);
// console.log(res);
// @lc code=end

